package com.lottery.game.core.modules.service.game.impl;

import com.lottery.game.common.base.service.impl.AbstractBaseServiceImpl;
import com.lottery.game.common.exception.BaseException;
import com.lottery.game.core.modules.entity.game.SysDict;
import com.lottery.game.core.modules.service.game.SysDictService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("sysDictService")
public class SysDictServiceImpl extends AbstractBaseServiceImpl<SysDict> implements SysDictService {
    @Override
    public List<SysDict> findByType(String type) {
        SysDict param = new SysDict();
        param.setType(type);
        return select(param);
    }

    @Override
    public List<SysDict> findByTypeAndLabel(String type, String label) {
        SysDict param = new SysDict();
        param.setType(type);
        param.setLabel(label);
        return select(param);
    }

    @Override
    public String findImageServerAddress() {
        List<SysDict> dicts = findByTypeAndLabel("server_ip", "img_server");
        return dicts.get(0).getValue();
    }

    @Override
    public String findPrivateKey() {
        List<SysDict> dicts = findByTypeAndLabel("privateKey", "privateKey");
        if (dicts.size() < 1) {
            throw new BaseException("系统未配置私钥");
        }
        return dicts.get(0).getValue();
    }
}
